import send_msg from '@feidao-factory/send-msg';

/**
 * 编码服务
 * @param action_id 系统参数action_id
 * @param session_id 系统参数session_id
 * @param spaceid 系统参数spaceid
 * @param systemid 当前项目systemid
 * @param pname 编码规则
 * @param setinfo 编码前缀
 * @param n 获取编码个数
 * @example doc_code(action_id, session_id, spaceid, systemid, pname, setinfo, n);
 */
export default async function doc_code(action_id: string, session_id: string, spaceid: string, systemid: string, pname: string, setinfo: string, n: number) {
	const msg = {
		n,
		pname,
		setinfo,
		spaceid,
		systemid
	};
	const data = await send_msg<{
		code: '1';
		msg: string;
		result: string;
		results: string[];
	}>(action_id, session_id, 'dataservice.finddoccode', msg);
	if (data.code === '1') {
		return data;
	} else {
		throw Error(data.msg);
	}
}
